'''

Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).

Note: The solution set must not contain duplicate subsets.

Example:

Input: [1,2,2]
Output:
[
  [2],
  [1],
  [1,2,2],
  [2,2],
  [1,2],
  []
]

'''

class Solution:
    def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
        '''
        20201009---李运辰
        
        1.最后一个*不能少；ps：表示指针
        
        '''
        re = []
        nums = sorted(nums)
        def helper(index: int, sub: [int]):
            for i in range(index, len(nums)):
                sub.append(nums[i])
                if sub[:] not in re: re.append(sub[:])
                helper(i+1, sub)
                sub.pop()

        helper(0, [])
        return [*re, []]
        